// 页面form 与 接口data 数据结构互相转换
// 废旧物
import dictUtil2 from '@/common/js/dictUtil2.js';
import {separator, imageDomain} from '@/common/js/resource.js';
import tool from '@/common/js/tools.js';
export default {
	/**
	 * 将接口返回的res.data转换成页面的formData
	 * @param {Object} data 接口返回的data
	 * @return {Object} 页面formData
	 */
	newForm(data) {
		/*
		BeiZhu: ""
		ChuLiDanWei: "11"
		ChuLiDate: "2024-04-11"
		ChuLiRen: "22"
		ChuLiRenLianXiFangShi: "33"
		ChuLiTime: "11:56"
		FeiQiWuFenLeiID: 29
		FeiQiWuFenLeiMingCheng: "废油"
		FeiQiWuZhaoPianUrl: ""
		ID: 1
		JiLiangDanWeiID: 10
		JiLiangDanWeiMingCheng: "公斤"
		QiYeID: 1
		ShuLiang: 4
		ZhuangTai: 1
		*/
		return {
			id: data.ID,
			companyId: data.QiYeID,
			handleTime: data.ChuLiDate + ' ' + data.ChuLiTime,
			company: data.ChuLiDanWei, // 处理单位
			contract: data.ChuLiRen, // 处理人
			contractMobile: data.ChuLiRenLianXiFangShi, // 处理人联系方式
			wasteId: data.FeiQiWuFenLeiID, // 餐厨废弃物分类 1餐余、2废油、9其他。
			waste: data.FeiQiWuFenLeiMingCheng, // 餐厨废弃物分类 1餐余、2废油、9其他。
			quantity: data.ShuLiang + '', // 数量
			unit: data.JiLiangDanWeiMingCheng, // 计量单位 选
			unitId: data.JiLiangDanWeiID, // 计量单位 选
			images1: tool.addImageDomain(data.FeiQiWuZhaoPianUrl), // 照片
			remark: data.BeiZhu, // 备注
		}
	},
	/**
	 * 将接口返回的res.data转换成页面的dataList
	 * @param {Array} list 接口返回的list
	 * @return {Object} 页面dataList
	 */
	newFormList(list) {
		/*
		BeiZhu: ""
		ChuLiDanWei: "11"
		ChuLiDate: "2024-04-11"
		ChuLiRen: "22"
		ChuLiRenLianXiFangShi: "33"
		ChuLiTime: "11:56"
		FeiQiWuFenLeiID: 29
		FeiQiWuFenLeiMingCheng: "废油"
		FeiQiWuZhaoPianUrl: ""
		ID: 1
		JiLiangDanWeiID: 10
		JiLiangDanWeiMingCheng: "公斤"
		QiYeID: 1
		RecordCount: 1
		ShuLiang: 4
		ZhuangTai: 1
		*/
		let arr = list.map(data => {
			return {
				id: data.ID,
				waste: data.FeiQiWuFenLeiMingCheng,
				quantity: data.ShuLiang,
				unit: data.JiLiangDanWeiMingCheng, // 计量单位
				handleTime: data.ChuLiDate + ' ' + data.ChuLiTime,
				images1: tool.addImageDomain(data.FeiQiWuZhaoPianUrl)
			}
		})
		return arr;
	},
	/**
	 * 将页面页面的formData转换成接口需要的data
	 * @param {Object} form 页面formData
	 * @return {Object} 传给接口的data
	 */
	newApiData(data) {
		/*
		company: "11"
		companyId: 1
		contract: "22"
		contractMobile: "33"
		handleTime: "2024-04-11 11:50"
		id: null
		images1: ""
		quantity: "4"
		remark: null
		unit: "桶"
		unitId: 15
		waste: ""
		wasteId: "29"
		_add_time_str: ""
		*/
		return {
			FeiQiChuLiID: data.id || '',
			QiYeID: data.companyId,
			ChuLiDate: data.handleTime.substring(0, 10), // 处理时间
			ChuLiTime: data.handleTime.substring(11, 16), // 处理时间
			ChuLiDanWei: data.company, // 处理单位
			ChuLiRen: data.contract, // 处理人
			ChuLiRenLianXiFangShi: data.contractMobile, // 处理人联系方式
			FeiQiWuFenLeiID: data.wasteId, // 餐厨废弃物分类 1餐余、2废油、9其他。
			ShuLiang: data.quantity, // 数量
			JiLiangDanWeiID: data.unitId, // 计量单位 选
			FeiQiWuZhaoPianUrl: data.images1.replaceAll(imageDomain, ''), // 照片
			BeiZhu: data.remark, // 备注
		}
	},
	// 比较新form和原form是否相同（无变化）
	compare(form1, form2){
		return form1.id             == form2.id            
		    && form1.companyId      == form2.companyId     
		    && form1.handleTime     == form2.handleTime    
		    && form1.company        == form2.company       
		    && form1.contract       == form2.contract      
		    && form1.contractMobile == form2.contractMobile
		    && form1.wasteId        == form2.wasteId       
		    && form1.waste          == form2.waste         
		    && form1.quantity       == form2.quantity      
		    && form1.unit           == form2.unit          
		    && form1.unitId         == form2.unitId        
		    && form1.images1        == form2.images1       
		    && form1.remark         == form2.remark
	},
}